<template>
    <!-- 导航栏 -->
    <van-nav-bar title="消费记录" left-arrow @click-left="back" fixed="true"/>

    <van-pull-refresh v-model="refreshing" @refresh="refresh">
        <van-tabs>
            <van-cell v-for="item in list" center
                :title="item.content" 
                :value="item.createtime" />
 
            <!-- <van-swipe-cell>
                <van-cell v-for="item in list" :border="false" :title="'消费内容：' + item.content"
                    :value="'消费时间：' + item.createtime" />

                <template #right>
                    <van-button square type="danger" text="删除" />
                </template>

            </van-swipe-cell> -->

        </van-tabs>
    </van-pull-refresh>
</template>
<script setup>

const { proxy } = getCurrentInstance();
const back = () => proxy.$router.go(-1);

let business = proxy.$cookies.get("business") ? proxy.$cookies.get("business") : {};
business = reactive(business);

//下拉刷新
let page = ref(1)
let loading = ref(false)
let finished = ref(false)
let refreshing = ref(false)


let list = ref([]);
onBeforeMount(() => {
    getRecordDate();
});

//获取消费记录
const getRecordDate = async () => {

    //如果刷新状态已经为true了，就要修改为false
    if (refreshing.value) {
        refreshing.value = false
    }

    //请求发送完毕后，加载状态也就完毕了
    loading.value = false

    var result = await proxy.$POST({
        url: "record/index",
        params: {
            busid: business.id,
        },
    });

    if (result) {
        list.value = result.data;
        console.log(result.data[0].createtime);
    }
}

//下拉刷新的方法
const refresh = async () => {
    //可以去掉定时器
    setTimeout(() => {
        page.value = 1
        list.value = []
        finished.value = false
        loading.value = true
        getRecordDate();
    }, 1000)
}

</script>
<style>
.van-cell{
    align-items: center;
}
</style>